#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int p[N], v[N], ans[N];
int bit[N];

int lowbit(int x) { return x & -x; }
void add(int x, int d) {
  for (int i = x; i <= n; i += lowbit(i)) bit[i] += d;
}
int query(int x) {
  int res = 0;
  for (int i = x; i > 0; i -= lowbit(i)) res += bit[i];
  return res;
}

void init(int n) { rep(i, 1, n) bit[i] = 0; }
void solve() {
  init(n);
  rep(i, 1, n) cin >> p[i] >> v[i];
  per(i, n, 1) {
    int l = p[i] + 1, r = n;
    while (l <= r) {
      int mid = (l + r) >> 1;
      int cnt = p[i] + query(mid);
      if (mid <= cnt)
        l = mid + 1;
      else
        r = mid - 1;
    }
    p[i] = l;
    add(p[i], 1);
    ans[p[i]] = v[i];
  }
  rep(i, 1, n) cout << ans[i] << " \n"[i == n];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> n) solve();
  return 0;
}